<template>
  <div>
    <van-popup v-model="show" position="bottom" :style="{ height: '45%' }">
      <div class="content_box">
        <van-nav-bar
          title="选择考试"
          left-text=""
          left-arrow
          @click-left="onClickLeft"
        />
        <div
          class="button"
          v-for="(item, index) in classifyList"
          :key="index"
          :class="active == index ? 'bgc' : ''"
          @click="onClickTab(index)"
        >
          <div class="content">
            <div>{{ item.title }}</div>
            <div>{{ item.brief }}</div>
          </div>
        </div>
      </div>
    </van-popup>

    <van-popup v-model="show2" position="bottom" :style="{ height: '30%' }">
      <div class="content_box">
        <van-nav-bar
          :title="this.list.title"
          left-text=""
          right-text=""
          left-arrow
          @click-left="onClickLeft2"
        />
        <div
          class="button"
          v-for="(item, index) in title"
          :key="index"
          :class="active1 == index ? 'bgc' : ''"
          @click="onClickTab2(index)"
        >
          <div class="content">
            <div>{{ item.title1 }}</div>
            <div>{{ item.title2 }}</div>
          </div>
        </div>
      </div>
    </van-popup>

    <van-popup v-model="show3" position="bottom" :style="{ height: '75%' }">
      <div class="content_box">
        <van-nav-bar
          :title="this.list.title"
          left-text=""
          left-arrow
          @click-left="onClickLeft3"
        >
        </van-nav-bar>
        <button v-show="isShow" @click="Complete">完成</button>
        <div
          class="button"
          v-for="(item, index) in showlist"
          :key="index"
          :class="active2 == index ? 'bgc' : ''"
          @click="onClickTab3(index)"
        >
          <div class="content">
            <div>{{ item.major_name }}</div>
          </div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { getFirstClassify, getClassify } from "../../http/api";
export default {
  data() {
    return {
      show: true,
      show2: false,
      show3: false,
      classifyList: [],
      active: -1,
      active1: -1,
      active2: -1,
      list: [],
      title: [{ title1: "在校生" }, { title2: "在职" }],
      id: 0,
      showlist: [],
      isShow: false,
    };
  },
  created() {
    this.getClassify();
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    async getClassify() {
      const res = await getFirstClassify();
      console.log(res);
      this.classifyList = res.data.data;
    },
    onClickTab(index) {
      this.active = index;
      // console.log(index);
      this.show = false;
      this.show2 = true;
      if (index === 0) {
        this.list = this.classifyList[0];
        this.id = this.list.id;
      } else if (index === 1) {
        this.list = this.classifyList[1];
        this.id = this.list.id;
      } else if (index === 2) {
        this.list = this.classifyList[2];
        this.id = this.list.id;
      } else if (index === 3) {
        this.list = this.classifyList[3];
        this.id = this.list.id;
      }
      console.log(this.list);
      this.getClassify();
    },
    onClickLeft2() {
      this.show = true;
      this.show2 = false;
    },
    onClickLeft3() {
      (this.show3 = false), (this.show2 = true);
    },
    async onClickTab2(index) {
      this.active1 = index;
      (this.show2 = false), (this.show3 = true);
      const res = await getClassify(this.id);
      console.log(res);
      this.showlist = res.data.data;
      console.log(this.showlist);
    },
    onClickTab3(index) {
      this.active2 = index;
      this.isShow = true;
    },
    Complete() {
      const title = this.list.title;
      const id = this.id;
      // console.log(id);
      this.$store.commit("ClassifyId", id);
      this.$store.commit("ClassifyName", title);
      this.show3 = false;

      this.$emit("onshow", this.data);
    },
  },
};
</script>

<style lang="scss" scoped>
.content_box {
  width: 90%;
  height: 100%;
  //   background-color: slateblue;
  margin: 0 auto;
}
.button {
  width: 100%;
  height: 55px;
  background-color: #f8f8f5;
  border-radius: 40px;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0.2rem;
}
.bgc {
  background-color: #f08300;
  color: #fff;
}
.content div:nth-child(1) {
  font-size: 15px;
}
.content div {
  width: 100%;
  font-size: 10px;
  margin-top: 5px;
}
button {
  width: 50px;
  font-size: 13px;
  border-radius: 40px;
  border: none;
  outline: none;
  background-color: #f08300;
  color: #fff;
  padding: 5px 5px;
  position: absolute;
  right: 30px;
  top: 12px;
  z-index: 666;
}
</style>